/*
 * logging.h
 *
 *  Created on: Aug 28, 2012
 *      Author: aortegag
 */

#ifndef LOGGING_H_
#define LOGGING_H_

/**
 * \defgroup LoggingMacros
 * Macros used to set the logging level
 * @{
 */
#define LOG_LEVEL_ERR		0 //!< An error which needs to be informed
#define LOG_LEVEL_WARN		1 //!< A warning we live with but need to inform
#define LOG_LEVEL_INFO		2 //!< Information about program state
#define LOG_LEVEL_DEBUG		3 //!< Debug information
#define LOG_LEVEL_TRACE		4 //!< Extra debug information
#define LOG_LEVEL_DATA		5 //!< Detailed extra debug information.

/**
 * \brief Select log level at compile time. This will be the highest log level
 * available at compile time.
 *
 **/
#define MAX_LOG_LEVEL	LOG_LEVEL_DATA
/** @} */

#include <stdio.h>
#define PRINTF	printf

// Default log level to MAX
extern int dsmblr_log_level;

#define _LOG(log_level, format, ...)	\
	if(LOG_LEVEL_##log_level <= dsmblr_log_level)	\
		PRINTF(format,  ##__VA_ARGS__)

#define LOG_ERR(format, ...)	\
	_LOG(ERR, "[ERROR] %s:%s():%d: " format, __FILE__, __FUNCTION__, \
									 __LINE__, ##__VA_ARGS__)

#if (MAX_LOG_LEVEL >= LOG_LEVEL_WARN)
#define LOG_WARN(format, ...)	\
	_LOG(WARN, "[WARNING] %s:%s():%d: " format,  __FILE__, __FUNCTION__, \
									   __LINE__, ##__VA_ARGS__)
#else
#define LOG_WARN(format, arg...) do {} while(0)
#endif

#if (MAX_LOG_LEVEL >= LOG_LEVEL_INFO)
#define LOG_INFO(format, ...)	\
	_LOG(INFO, format, ##__VA_ARGS__)
#else
#define LOG_INFO(format, arg...) do {} while(0)
#endif

#if (MAX_LOG_LEVEL >= LOG_LEVEL_DEBUG)
#define LOG_DEBUG(format, ...)	\
	_LOG(DEBUG, "[DEBUG] " format, ##__VA_ARGS__)
#else
#define LOG_DEBUG(format, arg...) do {} while(0)
#endif

#if (MAX_LOG_LEVEL >= LOG_LEVEL_TRACE)
#define LOG_TRACE(format, ...)	\
	_LOG(TRACE, "[TRACE] " format, ##__VA_ARGS__)
#else
#define LOG_TRACE(format, arg...) do {} while(0)
#endif

#if (MAX_LOG_LEVEL >= LOG_LEVEL_DATA)
#define LOG_DATA(format, ...)	\
	_LOG(DATA, "[DATA] " format, ##__VA_ARGS__)
#else
#define LOG_DATA(format, arg...) do {} while(0)
#endif





#endif /* LOGGING_H_ */
